%Continuation to question II_3
ds1_augm = augment_dataset(ds1);
ds2_augm = augment_dataset(ds2);
new1_aug = augment_dataset(new1);
new2_aug = augment_dataset(new2);
% option 2
M = (w1.P*mean(ds1_augm)+w2.P*mean(ds2_augm))';
S = w1.P*cov(ds1_augm)+w2.P*cov(ds2_augm);
delt = (mean(ds1_augm)-mean(ds2_augm))*(S^-1)*(mean(ds1_augm)-mean(ds2_augm))';
V_d = -M'*(S^-1)*(mean(ds1_augm)'-mean(ds2_augm)')+(w1.P-w2.P)/(2*w1.P*w2.P)*(1+delt*w1.P*w2.P);
v = (S^-1)*(mean(ds1_augm)-mean(ds2_augm))';
ne1 = sum(new1_aug*v + V_d <= 0); % data that classified to class 2
ne2 = sum(new2_aug*v + V_d > 0);
E_opt2 = w1.P*ne1/size(new1_aug,1)+w2.P*ne2/size(new2_aug,1);
disp(['for option 2, E_GL=',num2str(E_opt2)]);


ds1_augm_dim = ds1_augm(1:floor(50*w1.P),:);
ds2_augm_dim = ds2_augm(1:floor(50*w2.P),:);
M = (w1.P*mean(ds1_augm_dim)+w2.P*mean(ds2_augm_dim))';
S = w1.P*cov(ds1_augm_dim)+w2.P*cov(ds2_augm_dim);
delt = (mean(ds1_augm_dim)-mean(ds2_augm_dim))*(S^-1)*(mean(ds1_augm_dim)-mean(ds2_augm_dim))';
V_d = -M'*(S^-1)*(mean(ds1_augm_dim)'-mean(ds2_augm_dim)')+(w1.P-w2.P)/(2*w1.P*w2.P)*(1+delt*w1.P*w2.P);
v = (S^-1)*(mean(ds1_augm_dim)-mean(ds2_augm_dim))';
ne1 = sum(new1_aug*v + V_d <= 0); % data that classified to class 2
ne2 = sum(new2_aug*v + V_d > 0);
E_opt2_dim = w1.P*ne1/size(new1_aug,1)+w2.P*ne2/size(new2_aug,1);
disp(['for option 2, E_GL_dim=',num2str(E_opt2_dim)]);
